home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / Hsoi's App Shell 1.0a4 / Hsoi's App Shell Source / HASUtilFiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-28  |  4.3 KB  |  155 lines  |  [TEXT/CWIE]

  1. /*
  2.     HASUtilFiles.c from Hsoi's App Shell.  © 1995-1997 John C. Daub.  All rights reserved
  3.     
  4.     This file contains various "utility" functions used with our file handling routines.
  5.     More file related functions can be found in HASFiles.c
  6. */
  7.  
  8. #pragma mark ••• #includes •••
  9.  
  10. #ifndef _WASTE_
  11. #include "WASTE.h"
  12. #endif
  13. #include "HASGlobals.h"
  14. #ifndef __HSOIS_APP_SHELL__
  15. #include "HASMain.h"
  16. #endif
  17. #include "HASDialogs.h"
  18. #include "HASUtilFiles.h"
  19. #include "HASMiscEvents.h"
  20.  
  21. #pragma mark -
  22.  
  23. /*
  24.  *    When saving a file, this function will set the default place for the user to
  25.  *    save their file.  Just a couple low-mem manipulations...
  26.  */
  27.  
  28.  
  29.  
  30. void    HsoiSetDefaultDirectory( const FSSpec *spec )
  31. {
  32.     LMSetCurDirStore( spec->parID );
  33.     LMSetSFSaveDisk( -spec->vRefNum );
  34.     
  35.     return;
  36. }
  37.  
  38. /*
  39.  *    This is the dialog filter used for the Get/Put File dialogs.  It is very similar to
  40.  *    "regular" dialog filters, however we cannot use hsoiMyStandardDialogFilter for the
  41.  *    get/put file dialogs due to the SetDialogDefaultItem call (which messes up the
  42.  *    put file's cancel/replace dialog...try it and you'll see
  43.  */
  44.  
  45. pascal Boolean hsoiMySFDialogFilter( DialogRef dialog, EventRecord *event, short *item, void *yourData )
  46. {
  47. #pragma unused ( yourData )
  48.  
  49.     GrafPtr                savePort;
  50.     ModalFilterUPP        stdFilter = nil;
  51.     Boolean                reply = false;
  52.     OSErr                err;
  53.     short                whatEvent;
  54.     Boolean                handled = false;
  55.     
  56.     // set up the port
  57.     
  58.     GetPort( &savePort );
  59.     SetGrafPortOfDialog( dialog );
  60.     
  61.     //     intercept window events directed to widnows behind the dialog
  62.     
  63.     if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) )
  64.     {
  65.         whatEvent = event->message;
  66.         if ( (DialogRef)(event->message) != dialog ) 
  67.         {
  68.             if ( event->what == updateEvt )
  69.                 HsoiDoUpdate( (WindowRef)(event->message) );
  70.             else if ( event->what == activateEvt )
  71.                 HsoiDoActivate( (event->modifiers & activeFlag != 0), (WindowRef)(event->message) );
  72.  
  73.         } // end if (WindowRef)whatEvent != dialog
  74.     
  75.     }
  76.     
  77.     //    call the standard Dialog Manager filter procedure
  78.     
  79.  
  80.     err = GetStdFilterProc( &stdFilter );
  81.     if ( (err == noErr) && (!handled) )
  82.         reply = CallModalFilterProc( stdFilter, dialog, event, item );
  83.     
  84.     //    restore the port
  85.     SetPort( savePort );
  86.     
  87.     return reply;
  88.  
  89. }
  90.  
  91.  
  92. /*    The following 2 functions (CheckObjectLock and FSpCheckObjectLock) were taken
  93.     from MoreFiles 1.2.1, a code sample from Apple's DTS.  Here's some info from
  94.     the MoreFiles readme:
  95.     
  96.         A collection of File Manager and related routines
  97.  
  98.         by Jim Luther, Apple Macintosh Developer Technical Support
  99.         with significant code contributions by Nitin Ganatra, Apple Macintosh Developer
  100.         Technical Support
  101.         MoreFile Reference is by Eric Soldan
  102.         Copyright © 1992-1994 Apple Computer, Inc.
  103.         All rights reserved.
  104.     
  105.     Frankly, this is one amazing repository of all sorts of file-related things.  I'd
  106.     check it out if you can. (should be, as of this writing, on ftp.info.apple.com
  107.     in like the /Apple.Support.Services/Developer_Support/ or something like that).
  108.     Also, I think it's now being made available on the CodeWarrior CD's...check the
  109.     Reference CD.
  110.     
  111.     As of this writing (February 20, 1996), MoreFiles is in version 1.4.1.
  112.     thanx to Alex Rosen for answering my post on comp.sys.mac.programmer.help and pointing
  113.     out MoreFiles to me.
  114.     
  115.     WHAT DO THEY DO?  Oh duh...i should tell you huh?
  116.     
  117.     Both functions do the same thing:  check to see if the object is locked
  118.     (in this case, the object is a file).  This is using in HsoiWriteTextFile()
  119.     to prevent overwriting/deleting locked files.
  120.     
  121.     The only difference between these 2 functions are the arguments passed.
  122.     the first takes a vRefNum, dirID and a file name, the second takes an FSSpec
  123.     and then just calls the first based on the FSSpec (just makes for slighly
  124.     neater/readable code)
  125. */
  126.  
  127. pascal    OSErr    HsoiCheckObjectLock(short vRefNum, long dirID, StringPtr name)
  128. {
  129.     CInfoPBRec pb;
  130.     OSErr error;
  131.     
  132.     pb.hFileInfo.ioNamePtr = name;
  133.     pb.hFileInfo.ioVRefNum = vRefNum;
  134.     pb.hFileInfo.ioDirID = dirID;
  135.     pb.hFileInfo.ioFDirIndex = 0;    // use ioNamePtr and ioDirID
  136.     error = PBGetCatInfoSync(&pb);
  137.     
  138.     if ( error == noErr )
  139.     {
  140.         // check locked bit
  141.         if ( (pb.hFileInfo.ioFlAttrib & 0x01) != 0 )
  142.             error = fLckdErr;
  143.     }
  144.     return ( error );
  145. }
  146.  
  147. /*****************************************************************************/
  148.  
  149. pascal    OSErr    HsoiFSpCheckObjectLock(const FSSpec *spec)
  150. {
  151.     return ( HsoiCheckObjectLock(spec->vRefNum, spec->parID, (StringPtr)spec->name) );
  152. }
  153.  
  154.  
  155.